package com.power.home.ui.activity;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.power.home.common.Constant;
import com.power.home.common.util.SharePreferencesUtils;
import com.power.home.common.util.UIUtil;
import com.power.home.data.bean.PersonCenterBean;
import com.power.home.data.bean.UserInfoChildBean;
import com.power.home.di.component.AppComponent;
import com.power.home.di.component.DaggerMainMineComponent;
import com.power.home.di.module.MainMineModule;
import com.power.home.presenter.MainMinePresenter;
import com.power.home.presenter.contract.MainMineContract;
import com.power.home.R;
import com.power.home.ui.widget.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
@Route(path = "/android/vipDetailInfo")
public class VIPInfoActivity  extends BaseActivity<MainMinePresenter> implements MainMineContract.View{
   @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.vip_info_recycleview)
    RecyclerView recyclerView;
    private int userid = 0;
    UserInfoAdapter userInfoAdapter;
    List<UserInfoItemContainer> userInfoItemContainerList = new ArrayList<>();
    @Override
    public int setLayout() {
        return R.layout.activity_vippersoninfo;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(UIUtil.getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linearLayoutManager);
        userInfoAdapter = new UserInfoAdapter();
        recyclerView.setAdapter(userInfoAdapter);
        backListener(titleBar);
        userid = getIntent().getIntExtra(Constant.id,0);
        mPresenter.getUserInfo(String.valueOf(userid));
        return false;
    }

    @Override
    public void setListener() {

    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

        DaggerMainMineComponent.builder().appComponent(appComponent)
                .mainMineModule(new MainMineModule(this))
                .build().inject(this);
    }

    @Override
    public void getUserInfoSuccess(UserInfoChildBean userInfoChildBean) {
         UserInfoItemContainer nickNameContainer = new UserInfoItemContainer("昵称",userInfoChildBean.getNickName());
         UserInfoItemContainer phoneContainer = new UserInfoItemContainer("电话",userInfoChildBean.getPhone());
         String agentLevelString = userInfoChildBean.getAgentLevel();
         boolean  isHappinessVip = userInfoChildBean.isHappinessVip();
         UserInfoItemContainer agentLevelContainer = new UserInfoItemContainer("会员级别",agentLevel(agentLevelString,isHappinessVip));
         UserInfoItemContainer regiTimeContainer = new UserInfoItemContainer("注册时间",userInfoChildBean.getCreateTime());
         List<String> codes = userInfoChildBean.getCodeMarkets();
         String openWayString = "兑换码开通";
         String convertCodeString = "";
         if(codes == null || codes.size() == 0){
             openWayString = "线上支付";
         }else{
             convertCodeString = codes.get(0);
         }


         UserInfoItemContainer openWayContainer = new UserInfoItemContainer("开通方式",openWayString);
         UserInfoItemContainer codeContainer = new UserInfoItemContainer("兑换码",convertCodeString);
         UserInfoItemContainer vipExpireTimeContainer = new UserInfoItemContainer("会员到期时间",userInfoChildBean.getHappinessVipDueTime());
         UserInfoItemContainer inviteCodeContainer = new UserInfoItemContainer("邀请码",userInfoChildBean.getRecCode());
         userInfoItemContainerList.add(nickNameContainer);
         userInfoItemContainerList.add(phoneContainer);
         userInfoItemContainerList.add(agentLevelContainer);
         userInfoItemContainerList.add(regiTimeContainer);
         userInfoItemContainerList.add(openWayContainer);
         userInfoItemContainerList.add(codeContainer);
         userInfoItemContainerList.add(vipExpireTimeContainer);
         userInfoItemContainerList.add(inviteCodeContainer);
         userInfoAdapter.notifyDataSetChanged();
    }

    private String agentLevel(String agentLevel,boolean isHappinessVip){
        if(TextUtils.isEmpty(agentLevel)){
            return isHappinessVip ? "365会员" : "普通用户";
        }
        if(agentLevel.equals("AMBASSADOR")){
            return "联盟校长";
        }

        if(agentLevel.equals("SCHOOLMASTER")){
            return "同盟校长";
        }
           return isHappinessVip ? "365会员" : "普通用户";
    }
    @Override
    public void myPageSuccess(PersonCenterBean personCenterBean) {

    }

    public class UserInfoItemContainer {
      private String title;
       public UserInfoItemContainer(String title,String content){
           this.setTitle(title);
           this.setContent(content);
       }
        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        private String content;
    }

    public class UserInfoAdapter extends BaseQuickAdapter<UserInfoItemContainer, BaseViewHolder>{




        public UserInfoAdapter(){
            super(R.layout.team_info_item,userInfoItemContainerList);
        }
        @Override
        protected void convert(BaseViewHolder helper, UserInfoItemContainer item) {
            TextView tv_title = helper.getView(R.id.tv_title);
            TextView tv_content = helper.getView(R.id.tv_content);
            tv_title.setText(item.getTitle());
            tv_content.setText(item.getContent());
        }
    }
}
